package com.yigang.controller;

import java.text.ParseException;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yigang.entity.Color;
import com.yigang.service.ColorService;
import com.yigang.utils.ResultUtil;
/**
 * @author 陈佳祥
 *商品规格管理
 */
@Controller
@RequestMapping("/color")
public class ColorController {
	@Autowired
	private ColorService colorService;
	
	@RequestMapping("colorList")
	public String colorList() {
		return "jsp/color/colorList";
	}
	@RequestMapping("addColor")
	public String addColor() {
		return "jsp/color/addColor";
	}
	
	@RequestMapping("editColor/{color_id}")
	public String editColor(@PathVariable("color_id") int color_id, HttpSession session) {
		Color color = colorService.selectColorById(color_id);
	
		session.setAttribute("color", color);
		return "jsp/color/editColor";
	}
	
	//澧炲垹鏌ユ敼鏂规硶
	@RequestMapping("insertColor")
	@ResponseBody
	public ResultUtil insertColor(Color record) {
		colorService.insertSelective(record);
		return ResultUtil.ok();

	}

	@RequestMapping("deleteColorById")
	@ResponseBody
	public ResultUtil deleteColorById(int color_id) {
		
		return colorService.deleteByPrimaryKey(color_id);
	}

	@RequestMapping("getColorList")
	@ResponseBody
	public ResultUtil getColorList(Integer page, Integer limit, Color record) {

		return colorService.selectColorList(page, limit, record);
	}

	@RequestMapping("updateColor")
	@ResponseBody
	public ResultUtil updateColor(Color record) throws ParseException {
		
		return colorService.updateByPrimaryKeySelective(record);
	}
}
